<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>18.日期时间戳的使用与计算脚本执行时间</title>
</head>

<body>
  <script>
    let date = new Date();
    console.log(date); //Sat May 07 2022 17:31:31 GMT+0800 (中国标准时间)
    console.log(typeof date); // object
    console.log(date * 1);//x1 返回一个时间戳，1970年0时0分到现在的毫秒数 1651916017048
    const hd = Date();
    console.log(hd); //Sat May 07 2022 17:31:31 GMT+0800 (中国标准时间)
    console.log(typeof hd); //string
    console.log(hd * 1); //NaN
    //脚本执行时间
    const start = Date.now(); //获得当前时间戳
    for (let i = 0; i < 2000000; i++) { }
    const end = Date.now();
    console.log((end - start) / 1000 + 's');
    // 控制台调试
    console.time("for");
    for (let i = 0; i < 20000000; i++) { }
    console.timeEnd("for");
    //根据指定的日期与时间定义日期对象
    date = new Date('1990-9-22 03:22:18');
    console.log(date);
    console.log(date.getMonth());//月份从0开始
    console
    //多参数数值类型
    date = new Date(1990, 8, 22, 3, 22, 18);
    console.log(date);
    // 展示运算符 展开运算符
    let info = [1990, 8, 22, 3, 22, 18];
    date = new Date(...info);
    console.log(date);

  </script>
</body>

</html>